﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Tornado.Properties;

namespace Tornado
{
    public class Config
    {
        public static List<byte> hostRoles = new List<byte>();
        public static List<byte> guestRoles = new List<byte>();

        public static short HostPassword = 0;
        public static short GuestPassword = 0;
        public static short ReceivePassword = 0;
       
        public static void loadRoles()
        {
            hostRoles.Clear();
            guestRoles.Clear();

            string[] roleArr = Settings.Default.HostRoles.Split(new char[] { ',', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string c in roleArr)
            {
                byte b;
                if (byte.TryParse(c, out b))
                {
                    hostRoles.Add(b);
                }
            }
            roleArr = Settings.Default.GuestRoles.Split(new char[] { ',', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string c in roleArr)
            {
                byte b;
                if (byte.TryParse(c, out b))
                {
                    guestRoles.Add(b);
                }
            }
        }
        public static void load()
        {
            loadRoles();
        }

        public static bool isAcceptCmd(byte cmdCode, short password)
        {
            if (password.Equals(HostPassword))
                return hostRoles.Contains(cmdCode);
            return guestRoles.Contains(cmdCode);
        }


    }
}
